fix: don't inject attributes into comparison operators - #2
Merged
Conversation
The regex was matching `<` in less-than comparisons like
`count() < totalPages` and `userTier < minimumTier` as JSX tags.
Add isLikelyJsx() context check that walks backwards from each `<`,
skipping whitespace, to determine if it's JSX or a comparison:
- After `)`, `]`, quotes → comparison (end of expression)
- After `(`, `{`, `=`, `?`, `:`, operators → JSX (start of expression)
- After a keyword like `return` → JSX
- After any other identifier → comparison
Combined with the existing (?<!\w) lookbehind (for generics), this
handles all three classes of false positives: generics, comparisons
after identifiers, and comparisons after function calls.
Tested against ditto-app (real-world SolidJS app) with zero errors.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<in less-than comparisons (count() < totalPages,userTier < minimumTier,newIndex < props.images.length) as JSX opening tags, injectingdata-solid-sourceattributes into expressions and causing parse errorsisLikelyJsx()context checker that walks backwards from each<(skipping whitespace) to determine context:),], quotes → comparison (end of expression)(,{,=,?,:, operators → JSX (start of expression)return→ JSX(?<!\w)lookbehind (generics), handles all three false positive classes: generics, comparisons after identifiers, comparisons after function callsTest plan
bun startproduces zero transform errors (previously had errors inuseConversationHistory.tsx,Modal.tsx,ImageCarousel.tsx,usePairFeedback.tsx,useModal.tsx,useImageViewer.tsx,useSubjectViewer.tsx)🤖 Generated with Claude Code